<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>教师列表</title>
    #include("common/header.html")
    <link rel="stylesheet" href="/css/table.css"/>
</head>

<body>
<div class="admin-main">
    <fieldset class="layui-elem-field">
        <legend>教师列表</legend>
        <div class="layui-field-box layui-form">
            <table class="layui-table admin-table">
                <thead>
                <tr>
                    <th>昵称</th>
                    <th>性别</th>
                    <th>学历</th>
                    <th>单位</th>
                    <th>学习币</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="pager">
                </tbody>
            </table>
        </div>
    </fieldset>
    <!--<div class="admin-table-page">-->
    <div class="page-table-box" id="page" style=" width:1000px; margin:0 auto; margin-top:100px;"></div>
    <!--</div>-->
</div>
</body>

<script type="text/javascript">

    $(function () {
        pageList(1);
    });

    function pageList(pageNum) {

        $.ajax({
            url: "/teacher/page",
            type: "post",
            dataType: "json",
            data: {"pageNum": pageNum, "pageSize": window.page.pageSize},
            success: function (r) {

                console.log(r);

                if (r.code == -1) {
                    return;
                }

                page(pageNum, r.data.total);

                $("#pager").html("");

                var str = "";

                $.each(r.data.list, function (n, value) {
                    str += '<tr>';
                    str += '<td>' + convert(value.nickname) + '</td>';
                    str += '<td>' + convert(value.sex) + '</td>';
                    str += '<td>' + convert(value.edu) + '</td>';
                    str += '<td>' + convert(value.company) + '</td>';
                    str += '<td>' + convert(value.money) + '</td>';
                    str += '<td>';
                    str += '<a onclick="addTop(' + value.id + ')" class="layui-btn layui-btn-normal layui-btn-mini">推荐</a>';
                    str += '<a onclick="info(' + value.id + ')" class="layui-btn layui-btn-mini">详情</a>';
                    str += '<a onclick="pay(' + value.id + ')" class="layui-btn layui-btn-danger layui-btn-mini">结算薪酬</a>';
                    str += '</td>';
                    str += '</tr>';
                });

                $("#pager").html(str);
            }
        });
    }


    var layer;
    layui.use('layer', function () {
        layer = layui.layer;
    });


    function info(id) {
        layer.open({
            type: 2,
            title: '详情',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['650px', '450px'],
            content: '/teacher/' + id,
        });
    }

    function pay(id) {
        layer.open({
            type: 2,
            title: '结算薪酬',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['600px', '200px'],
            content: '/teacher/pay',
            btn: ['确定', '取消'],
            yes: function (index, layero) {

                //询问框
                layer.confirm('确定结算?', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    var body = layer.getChildFrame('body', index);
                    var money = body.find("#money").val();

                    if (money == "") {
                        layer.msg("请输入数字!");
                        return;
                    }

                    if (!/^[0-9]*$/.test(money)) {
                        layer.msg("请输入数字!");
                        return;
                    }

                    $.ajax({
                        url: "/teacher/pay",
                        type: "put",
                        dataType: "json",
                        data: {
                            "id": id,
                            "money": money
                        },
                        success: function (r) {
                            console.log(r);

                            if (r.code == -1) {
                                layer.msg(r.msg);
                                return;
                            }
                            layer.close(index);
                            layer.msg('结算成功!', {time: 1000}, function () {
                                location.reload();
                            });
                        }
                    });
                });
            }
        });
    }

    function addTop(id) {
        //询问框
        layer.confirm('确定推荐?', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                url: "/top/",
                type: "post",
                dataType: "json",
                data: {"target": id, "type": 2},
                success: function (r) {
                    console.log(r);

                    if (r.code == -1) {
                        layer.msg(r.msg);
                        return;
                    }

                    layer.msg('操作成功!');
                }
            });
        });
    }


</script>

</html>